local diaoli_viewas = fk.CreateSkill{
  name = "hanqing__diaoli_viewas&",
}

Fk:loadTranslationTable{
  ["hanqing__diaoli_viewas&"] = "调力",
  [":hanqing__diaoli_viewas&"] = "你可以选择手牌与“调力”牌中四张花色各不同的牌，将这些牌当一张【桃】使用。",
}

diaoli_viewas:addEffect("viewas", {
  anim_type = "support",
  mute_card = false,
  pattern = "peach",
  prompt = "#hanqing__diaoli-peach",
  expand_pile = function (self, player)
    local ids = {}
    for _, p in ipairs(Fk:currentRoom().alive_players) do
      if p:hasSkill("hanqing__diaoli") and #p:getPile("hanqing__diaoli") > 0 then
        table.insertTable(ids, p:getPile("hanqing__diaoli"))
      end
    end
    return ids
  end,
  handly_pile = true,
  card_filter = function(self, player, to_select, selected)
    return table.every(selected, function (id)
      return Fk:getCardById(id):compareSuitWith(Fk:getCardById(to_select), true)
    end) and
    (table.contains(player:getHandlyIds(), to_select) or
      table.find(Fk:currentRoom().alive_players, function (p)
        return p:hasSkill("hanqing__diaoli") and table.contains(p:getPile("hanqing__diaoli"), to_select)
      end))
  end,
  view_as = function(self, player, cards)
    if #cards ~= 4 then return end
    local card = Fk:cloneCard("peach")
    card:addSubcards(cards)
    card.skillName = "hanqing__diaoli"
    return card
  end,
  enabled_at_play = function (self, player)
    return table.find(Fk:currentRoom().alive_players, function (p)
      return p:hasSkill("hanqing__diaoli") and #p:getPile("hanqing__diaoli") > 0
    end) and #player:getViewAsCardNames("hanqing__diaoli", {"peach"}) > 0
  end,
  enabled_at_response = function (self, player, response)
    return not response and
      table.find(Fk:currentRoom().alive_players, function (p)
        return p:hasSkill("hanqing__diaoli") and #p:getPile("hanqing__diaoli") > 0
      end) and #player:getViewAsCardNames("hanqing__diaoli", {"peach"}) > 0
  end,
})

diaoli_viewas:addAI(nil, "vs_skill")

return diaoli_viewas
